package com.sychip.fhc.di

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import com.sychip.fhc.app.pref.PrefDataStoreIf
import com.sychip.fhc.app.pref.PrefDataStoreImpl
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton


@Module
@InstallIn(SingletonComponent::class)
object PrefDataStoreProvideModule {

    private val Context.prefDS by preferencesDataStore(name = "app_preference_datastore")

    @Provides
    @Singleton
    fun providePrefDataStore(
        @ApplicationContext context: Context
    ): DataStore<Preferences> = context.prefDS

}


@Module
@InstallIn(SingletonComponent::class)
abstract class PrefDataStoreBindModule {

    @Singleton
    @Binds
    abstract fun bindPrefDataStore(dataStoreImpl: PrefDataStoreImpl): PrefDataStoreIf
}